<?php
/**
 * Hesperos library for Zend Framework
 *
 * This script is protected by copyright. It's use, copying, modification
 * and distribution without written consent of the author is prohibited.
 *
 * @category    Hesperos
 * @package     Translate
 * @author      Krzysztof Kardasz <krzysztof.kardasz@gmail.com>
 * @copyright   Copyright (c) 2011 Krzysztof Kardasz
 * @license     http://www.gnu.org/licenses/lgpl-3.0.txt  GNU Lesser General Public
 * @version     1.0 $Id$
 * @link        http://code.google.com/p/hesperos/
 */

/**
 * Menadżer tłumaczeń
 *
 * @category    Hesperos
 * @package     Translate
 * @author      Krzysztof Kardasz <krzysztof.kardasz@gmail.com>
 * @copyright   Copyright (c) 2011 Krzysztof Kardasz
 * @version     1.0 $Id$
 */
class Hesperos_Translate_Manager
{
    /**
     * Zend Translate
     *
     * @var null|Zend_Translate
     */
    static private $_translate = null;

    /**
     * Zwraca obiekt translatora
     *
     * @return null|Zend_Translate
     */
    public static function getTranslate ()
    {
        return self::$_translate;
    }

    /**
     * Dodaje tłumaczenie (gettext)
     *
     * @param string $file ścieżka do pliku
     * @param string $locale wersja językowa
     * @return void
     */
    public static function addTranslation ($file, $locale)
    {
        if(self::$_translate === null) {
            Zend_Translate_Adapter::setCache(Hesperos_Cache_Manager::getI18n());
            self::$_translate = new Zend_Translate (
                array(
                    'adapter' => 'gettext',
                    'content' => $file,
                    'locale'  => $locale
                )
            );
        } else {
            self::$_translate->addTranslation (
                array(
                    'content' => $file,
                    'locale'  => $locale
                )
            );
        }
    }
}